﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StartStop.ServiceResources;
using System.Data.SqlClient;
using System.Data; 

namespace StartStop.Helpers
{
    public class DetailedStat
    {
        public const string LiveConnectionString = "data source=v2.startstop.me;initial catalog=startstop;persist security info=True;user id=sa;password=PASSWORD;";

        public static Int64 LookUpDetailedStatIDfromGuid(Guid DetailStatGUID)
        {
            Int64 _return = -1;

            string sqlreturn = Sql.ExecuteScalar("select DetailStatID from DetailStat where DetailStatGUID = @passedvalue", DetailStatGUID.ToString());
            if (sqlreturn != "")
            {
                _return = Int64.Parse(sqlreturn);
            }

            return _return; 
        }

        public static StatDescription LoadDetailStat(Int64 DetailStatID)
        {
            StatDescription oStat = new StatDescription();

            SqlConnection conn = new SqlConnection(LiveConnectionString);
            conn.Open();

            SqlCommand cmd = new SqlCommand(@"
                        select top 1 * from DetailStat where DetailStatID = @DetailStatID
            ", conn);
            cmd.Parameters.AddWithValue("@DetailStatID", DetailStatID);

            DataTable _returnDataTable = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            da.Fill(_returnDataTable);
            foreach (DataRow oRow in _returnDataTable.Rows)
            {
                oStat.OverviewID = Int64.Parse(oRow["OverviewID"].ToString());
                oStat.Name = oRow["NameOfStat"].ToString(); 
                oStat.Description = oRow["DetailOfStat"].ToString(); 
                oStat.DataType = (StartStop.ServiceResources.StatDescription.StatDateType)int.Parse(oRow["DataType"].ToString()); 

            }


            return oStat; 
        }

        public static MessageResponse UpdateStat(StartStop.ServiceResources.StatDescription oDesc)
        {
            MessageResponse oResponse = new MessageResponse();

            SqlConnection conn = new SqlConnection(LiveConnectionString);
            conn.Open();

            SqlCommand cmd = new SqlCommand(@"
                        insert into 
            ", conn);


            return oResponse; 

        }

    }
}
